import BPObject from "./BPObject";
import Config from './Config';

export default class Cell extends BPObject {


    constructor(type) {
        super(type);
        this.roundRectAngle = 20;
        this.lineWidth = 5;
        if (type) {
            let config = Config[type];

            this.labelCom.string = config.name;

            this.width = config['width'];
            this.height = config['height'];


            if (config['out']) {
                this.out = config['out'];
            } else {
                this.out = null;
            }
            if (config['in']) {
                this.in = config['in'];
            } else {
                this.in = null;
            }
        }

    }
    render(graphics: cc.Graphics, labelLayer: cc.Node) {
        graphics.lineWidth = this.lineWidth;
        graphics.fillColor = this.fillColor;
        graphics.strokeColor = this.lineColor;
        graphics.roundRect(this.x - this.width * 0.5, this.y - this.height * 0.5, this.width, this.height, this.roundRectAngle);
        graphics.fill();
        graphics.stroke();
        console.log("this ,out", this.out);
        this.labelNameNode.parent = labelLayer;
        this.labelNameNode.y = this.y + this.height * 0.5 - 20;
        if (this.out) {
            this.drawOut(graphics);
        }
        if (this.in) {
            this.drawIn(graphics);
        }
        this.drawParam();
    }
    drawIn(graphics: cc.Graphics) {
        graphics.moveTo(0, 0);
        graphics.lineTo(0, 100);
        graphics.lineTo(50, 50);
        graphics.fill();
    }
    drawOut(graphics: cc.Graphics) {
        console.log("绘制出节点");
        graphics.lineWidth = this.lineWidth + 2;
        let pointList = [cc.v2(0, -30), cc.v2(0, 30), cc.v2(40, 0), cc.v2(0, -30)];

        for (let i = 0; i < pointList.length; i++) {
            let pos = pointList[i];
            pos = pos.multiplyScalar(0.5);
            // pos = pos.add(cc.v2(this.width * 0.5, this.height * 0.5))

        }

        graphics.moveTo(pointList[0].x + this.width * 0.5 - 40, pointList[0].y + this.height * 0.5 - 60);

        for (let i = 1; i < pointList.length; i++) {
            graphics.lineTo(pointList[i].x + this.width * 0.5 - 40, pointList[i].y + this.height * 0.5 - 60);
        }
        graphics.fill();
        graphics.stroke();
    }
    drawParam() {
        let config = Config[this.type];
        let params = config['params'];
        console.log("params", params);
    }
}